﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace com.dbo
{
    public class Domain
    {
        com.net.Domain p = new com.net.Domain();

        public Domain() { }
        public Domain(com.net.Domain data)
        {
            p = data;
        }
        public com.net.Domain Data { get { return p; } set { p = value; } }

        public bool Fetch()
        {
            DataTable dt = com.dbo.DB.getTable("select * from adc_domain");
            if (dt.Rows.Count == 0)
                return false;

            p.DomainID = int.Parse(dt.Rows[0][0].ToString());
            p.DomainName = dt.Rows[0][1].ToString();
            p.Note = dt.Rows[0][2].ToString();
            return true;
        }
        public bool Add()
        {
            SqlCommand cmd = com.dbo.DB.getCmdSp("adddomain");
            cmd.Connection.Open();
            cmd.Parameters.AddWithValue("domainid", p.DomainID);
            cmd.Parameters.AddWithValue("domain", p.DomainName);
            cmd.Parameters.AddWithValue("note", p.Note);
            int i = cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            return i == 1;
        }
        public bool Update()
        {
            SqlCommand cmd = com.dbo.DB.getCmdSp("updatedomain");
            cmd.Connection.Open();
            cmd.Parameters.AddWithValue("domainid", p.DomainID);
            cmd.Parameters.AddWithValue("domain", p.DomainName);
            cmd.Parameters.AddWithValue("note", p.Note);
            int i = cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            return i == 1;
        }
        public bool Delete()
        {
            SqlCommand cmd = com.dbo.DB.getCmdSp("deldomain");
            cmd.Connection.Open();
            cmd.Parameters.AddWithValue("domainid", p.DomainID);
            int i = cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            return i == 1;
        }
    }
}

